package EjemplosEventosBasicos;

import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;


public class EjemploListSelectionListener2 {
	public void montarVentana (){
		JFrame frame = new JFrame();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		String[] datos = new String[]{"Uno","Dos","Tres","Cuatro","Cinco"};
		JList list = new JList(datos);
		
		list.addListSelectionListener(new ListSelectionListener(){

			public void valueChanged(ListSelectionEvent e) {
				System.out.println("Valor elegido diferente");
				System.out.println(((JList)e.getSource()).getSelectedValue());
			}
			
		});
		
		frame.add(list);
		frame.setVisible(true);
		frame.pack();
	}
	
	public static void main (String[] args){
		EjemploListSelectionListener2 elsl = new EjemploListSelectionListener2();
		elsl.montarVentana();
	}
}
